include("shared.lua")

function ENT:Initialize()
	self.IsWorking = false
	self.bar = 0
	self.timeToStart = false
	self.WeedNeeded = 15
end


function ENT:Draw()

	self:DrawModel()

	local Pos = self:GetPos()
	local Ang = self:GetAngles()

	surface.SetFont("HUDNumber5")
	local TextWidth = surface.GetTextSize("Money printer")

	Ang:RotateAroundAxis(Ang:Up(), 180)
	Ang:RotateAroundAxis(Ang:Forward(), 40)

	local placeholder = 0

	cam.Start3D2D(Pos + Ang:Up() * 20 + Ang:Forward()*15.5 -Ang:Right()*15, Ang, 0.11)
		draw.RoundedBox(0,-140,0,289,220,Color(0,0,0,255))
		draw.DrawText("Weed contained: ".. self:Getweedbags() .." oz", "ChatFont",-100,65+30,Color(255,255,255,255),0)
		draw.DrawText("Weed needed to compact: ".. self.WeedNeeded .." oz", "ChatFont",-120,65+110,Color(255,255,255,255),0)
		if self.IsWorking then
			local length = (self.bar/self.CompactTimer)*190
			draw.RoundedBox(2,-102,87+30,194,27,Color(222,222,222,100))
			draw.RoundedBox(2,-100,90+30,length,20,Color(255,0,0,255))
		end

	cam.End3D2D()
end

function ENT:Think()

	if self.timeToStart and !self.IsWorking then
		self.timeToStart=false
		self.StartTime=CurTime()
		self.EndTime = CurTime() + self.CompactTimer
		self.IsWorking=true
	end



	if self.IsWorking and CurTime() < self.EndTime then
		self.bar = CurTime() -self.StartTime
	else
		self.IsWorking=false
	end


	
end

net.Receive("startTheBar", function() 
	ent=net.ReadEntity()
	tim=tonumber(net.ReadString()) 
	
	ent.timeToStart=true
	ent.CompactTimer=tim
end)
	